import React, { Component } from 'react';
import './App.css';
import axios from "axios";
import { BrowserRouter as Router, Route } from "react-router-dom";
import Login from './components/Login'
import myIndex from './components/Index'
import storageUtils from './utils/StorageUtils'


class App extends Component {


  state = {
    collapsed: false,
    menuList:[],
    jump:false
  };


  onCollapse = (collapsed) => {
    console.log(collapsed);
    this.setState({
       collapsed
     });
  }

  getMenu=()=>{
    let url = "http://t.weather.sojson.com/api/weather/city/101010100";
    axios.get(url)
    .then(function (response) {
      // handle success
      // console.log(response);
    })
    .catch(function (error) {
      // handle error
      console.log(error);
    });
  }
 

  //后台设置 允许跨域
    getMenu3=()=>{
    let url = 'http://10.2.180.158:8080/getMenu';

    let list;
    axios.get(url)
    .then((response)=> {
      // handle success
      console.log(response.data.data);
      list = response.data.data;
      this.setState({
        menuList:list,
        redirect:false
      })
    })
    .catch(function (error) {
      // handle error
      console.log(error);
    });
  }




  componentDidMount(){


    let user = storageUtils.get('user');
    console.log(user)

    let flag = user.name!='邓明'? true :false;

    if(flag){

      this.setState({
        jump:true
      })
      // window.location.href='/index';
    }else{

      this.setState({
        jump:false
      })
      // window.location.href='/login';
    }
    // if(user.name!='邓明'){
    //   console.log(user.name)

  }

  componentDidUpdate(){
    // if(this.state.jump){
    //   window.location.href='/index';
    // }else{
    //   window.location.href='/login';
    // }
  }

  handleRouter=(key,menuName)=>{
      this.refs.tab.add(key,menuName);
  }


  render() {
    
    
  
    return (
      <Router>
        
        <div>
          <Route exact  path="/" component={Login}/>
           <Route path="/index" component={myIndex} />
          <Route path="/Login" component={Login} /> 
          </div>
     </Router>
    );

  }
}

export default App;
